package com.ychs.lawyer.controller;

import com.ychs.lawyer.DTO.RoleMenu;
import com.ychs.lawyer.bean.R;
import com.ychs.lawyer.bean.Role;
import com.ychs.lawyer.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: clh
 * @Date: 2024/07/25/18:55
 * @Description:
 */
@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation("通过角色Id获取角色名称")
    @GetMapping("/getRoleNamekById")
    public R<?> getRoleNamekById(Integer userId) {
        String roleName = roleService.getRoleNamekById(userId);
        return R.success(roleName);
    }


    @ApiOperation("获取所有角色")
    @GetMapping("/getRoles")
    public R<?> getRoles() {
        List<Role> roles = roleService.getRoles();
        return R.success(roles);
    }

    @ApiOperation("修改角色")
    @PostMapping("/editRole")
    public R<?> editRole(@RequestBody RoleMenu roleMenu) {
        Boolean res = roleService.editRole(roleMenu);
        return res?R.success():R.fail();
  }

   @ApiOperation("添加角色")
   @PostMapping("/addRole")
    public R<?> addRole(@RequestBody RoleMenu roleMenu) {
        Boolean res = roleService.addRole(roleMenu);
        return res?R.success():R.fail();
  }

    @ApiOperation("查询角色名称")
    @GetMapping("/selectRoleName")
    public R<?> selectRoleName() {
        List<Role> roles = roleService.selectRoleName();
        return R.success(roles);
  }

    @ApiOperation("删除角色")
    @GetMapping("/deleteRole")
    public R<?> deleteRole(Integer roleId) {
        int res = roleService.deleteRole(roleId);
       return res>0?R.success():R.fail();
  }


}
